package com.easy.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.Product;
import com.easy.common.service.IProductService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {
@Autowired
IProductService productservice;
@PostMapping("/")
public ResultData isnert(@RequestBody Product product){
    Product data= productservice.insert(product);
    return ResultData.success(data);
}
@PutMapping("/")
public ResultData update(@RequestBody Product product){
   Product data=productservice.update(product);
   return ResultData.success(data);
}
@DeleteMapping("/{id}")
public ResultData delete(@PathVariable Integer id){
    int result=productservice.delete(id);
    if (result>=1){
        return ResultData.success("200","删除成功");
    }else {
        return ResultData.fail();
    }
}
@GetMapping("/{id}")
public ResultData getByID(@PathVariable Integer id){
Product product=productservice.getByID(id);
return ResultData.success(product);
}
@GetMapping("/page")
public ResultData getListByPage(IPage page, Product product){
List<Product> data=productservice.getListByPage(page,product);
return  ResultData.success(data);
}
    @GetMapping("/list")
    public ResultData getList(Product product){
        List<Product> data=productservice.getList(product);
        return  ResultData.success(data);
    }
}
